<?php
//random utilities
class Util
{
	function Util()
	{

	}

	function clean($string)
	{
		return mysql_real_escape_string($string);
	}

	function cleanRequest()
	{
		foreach($_REQUEST as $name => $value)
		{
			$_REQUEST[$name] = Util::clean($value);
		}
	}

	function optimizeTables()
	{
		$result = query('SHOW TABLES') 
			or 
		die('Cannot get tables');
			
	 	while($table = mysql_fetch_row($result))
		{
			query('OPTIMIZE TABLE '.$table[0]) 
				or 
			die('Cannot optimize '.$table[0]);
		}
		
		echo "Database succesfully optimized!";
	}
	
	function getThemes()
	{
		//directory path can be either absolute or relative
		$dirPath = "./templates";
		
		//aray of themes
		$themes = array();
		
		// open the specified directory and check if it's opened successfully
		if ($handle = opendir($dirPath)) 
		{
		   // keep reading the directory entries 'til the end
		   while (false !== ($file = readdir($handle))) 
		   {
		      // just skip the reference to current and parent directory
		      if ($file != "cache" && stripos($file,".") !== 0) 
		      {
		         if (is_dir("$dirPath/$file")) 
		         {
		            // found a directory, do something with it?
		            $themes[] = $file;
		         }
		      }
		   }

	   		// ALWAYS remember to close what you opened
	   		closedir($handle);
		}
		
		return $themes;
	}
	

}

?>